<template>
  <div class="compareWrapper">
    <compareDataMenu :tableData="tableData" />
  </div>
</template>

<script>
import compareDataMenu from '../../../components/sd/compareDataMenu.vue'
import Com from '../../../common/js/com.js'
import MixinSD from '../../../store/sd/mixinsSd.js'
export default {
  mixins: [MixinSD],
  data () {
    return {
      tableData: []
    }
  },
  created () {
    this.getMapinfo()
    this.getAreaList()
    this.getDeviceParams() // 获取用户设备接收参数
  },
  methods: {
    getMapinfo () { // 获取设备点位接口
      var ts = Com.stringTime(new Date())
      var data = {
        account: window.localStorage.getItem('account'),
        token: window.localStorage.getItem('token'),
        ts
      }

      const that = this
      this.getMapInfoSD(data).then(function (value) {
        const result = value.data.data
        // props传参
        that.tableData = result.list.filter(item => {
          return item.code !== null && item.type !== '17'
        })
        that.tableData.forEach((item, i) => {
          item.key = i
          item.id = i < 9 ? '0' + (i + 1) : i + 1
          item.time = Com.stringTime(new Date())
        })

        // store参数
        /* 表格默认数据 */
        // const tableDataNew = result.list.filter(item => {
        //   return item.code !== null && item.type !== '17'
        // })
        // tableDataNew.forEach((item, i) => {
        //   item.key = i
        //   item.id = i < 9 ? '0' + (i + 1) : i + 1
        // })
        // that.$store.commit('updateDataTable', tableDataNew)

        /* 表格默认选中列 */
        // const selectedRowKeys = []
        // const selectedRows = []
        // if (tableDataNew) { // 设置表格默认选择列
        //   var len
        //   if (tableDataNew.length < Com.selectedNum) {
        //     len = tableDataNew.length
        //   } else {
        //     len = Com.selectedNum
        //   }
        //   if (tableDataNew.length > 0) {
        //     for (var i = 0; i < len; i++) {
        //       selectedRowKeys.push(i)
        //       selectedRows.push(tableDataNew[i])
        //     }
        //   }
        // }

        // const selectedTable = {}
        // const pageArr = ['menu1', 'menu2', 'menu3', 'menu4']
        // for (let i = 0; i < (pageArr.length - 1); i++) {
        //   selectedTable[pageArr[i]] = [{ selectedRows: selectedRows, selectedRowKeys: selectedRowKeys }]
        // }
        // that.$store.commit('updateSelectedTable', selectedTable)
      })
    },
    getAreaList () { // 获取地区列表下的国控空气站
      var ts = Com.stringTime(new Date())
      var data = {
        account: window.localStorage.getItem('account'),
        is_all: 1,
        is_gkz: 1,
        token: window.localStorage.getItem('token'),
        ts
      }
      const that = this
      this.getAreaListSD(data).then(function (value) {
        const result = value.data.data
        that.areaList = result
      })
    },
    getDeviceParams () { // 获取用户设备接收参数
      var ts = Com.stringTime(new Date())
      var data = {
        account: window.localStorage.getItem('account'),
        token: window.localStorage.getItem('token'),
        ts
      }
      const that = this
      this.getDeviceParamsSD(data).then(function (value) {
        const result = value.data.data
        that.$store.commit('updateEparam', result)
      })
    }
  },
  components: {
    compareDataMenu
  }
}
</script>

<style lang="less" scoped>
.compareWrapper {
  height: 100%;
  width: 100%;
}
</style>
